package com.situ.hibernate.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
    private static SessionFactory sessionFactory = null;

    static {
        // Configuration获取加载配置文件的管理类
        Configuration configuration = new Configuration();
        configuration.configure();// 默认加载的是classpath:hibernate.cfg.xml
        // 创建SessionFactory工厂
        sessionFactory = configuration.buildSessionFactory();
    }


    public static  Session openSession() {
        // 创建Session（代表一个会话，与jbbc中的Connection非常像）
        Session session = sessionFactory.openSession();
        return  session;
    }

}
